package com.qing.springbootinit.bizmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

// * @author <a href="https://github.com/qingfengzy">qingfengzy</a>
//重点！！！，先运行这个文件创建mq队列，不然异步功能会提示无法找到mq——channel！！！！

public class BiInitMain {

    public static void main(String[] args) {


        try {
            ConnectionFactory factory = new ConnectionFactory();
            factory.setHost("localhost");
            Connection connection= factory.newConnection();
            Channel channel = connection.createChannel();

            String EXCHANGE_NAME = BiMqConstant.BI_EXCHANGE_NAME;
            channel.exchangeDeclare(EXCHANGE_NAME,"direct");

            String QUEUE_NAME = BiMqConstant.BI_QUEUE_NAME;
            channel.queueDeclare(QUEUE_NAME,true,false,false,null);
            channel.queueBind(QUEUE_NAME,EXCHANGE_NAME, BiMqConstant.BI_ROUTE_KEY);

        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (TimeoutException e) {
            throw new RuntimeException(e);
        }

    }
}
